home *** CD-ROM | disk | FTP | other *** search
- Path: in2.uu.net!interaccess!d146
- From: jap@interaccess.com (Jeff Pleimling)
- Newsgroups: comp.lang.c
- Subject: Re: Printing to LPT1 Printer from within program
- Followup-To: comp.os.msdos.programmer
- Date: Wed, 24 Jan 96 21:49:38 GMT
- Organization: none
- Message-ID: <4e69fe$8hh@nntp.interaccess.com>
- References: <4e5ee9$m28_001@pr.mcs.net>
- NNTP-Posting-Host: d146.w.interaccess.com
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4e5ee9$m28_001@pr.mcs.net>,
- mdp@mika-sys.com (Michael D. Perry) wrote:
- >I have just started taking a C programming class and am using Borland
- >C++ v4.0 at home. Both my teacher and I are stumped as to how to
- >print to a LPT (Line Printer) device from within the program.
-
- Printing (under any operating system) is outside of the scope of
- the C language and should be discussed on an operating system
- specific group (comp.os.msdos.programmer in this case).
-
- >I have read the FAQ and there are some references to this but not
- >enough that I can quite figure it out. As near as I can figure you
- >can use iostreams or fprintf() with the later appearing to be the
- >simpler of the two. With that, from what I have seen, one uses a
- >filename of stdprn but I get an error message when compiling. My
- >guess is that there is a header file or a definition/declaration
- >statement that needs to be referenced.
-
- iostreams is C++, this is a C newsgroup.
-
- stdprn is not a filename. With most MS-DOS compilers, stdprn is
- a pre-opened file *handle* that points to the PRN device (which,
- in turn, usually points to LPT1). It is used like any other open
- file handle (i.e. "fprintf(stdprn, "This goes to the printer\n" ).
- Also, even though it is called stdprn it is *anything* but standard
- (as some people moving from dos to UNIX,Mac,... have found out).
- See below for a better approach.
-
- >I have looked at lots of materials on the Internet, quite a few books,
- >and hours in the on-line help and manuals for Borland C++ without
- >finding anything much about this. So either I am incredibly stupid
- >because the answer is so obvious that no one writes about it or it is
- >a little more obscure and someone maybe should write it into an FAQ?
-
- a) you're not stupid, just looking in the wrong place &
- b) the comp.os.msdos.programmer FAQ *probably* tells how, the
- most I expect the comp.lang.c FAQ to say is that it depends on the OS
- (even though I haven't looked).
-
- A *much* better way (IMHO) is to open the printer port using fopen().
- That way you can make it user configurable (what if they have a serial
- printer hooked to COM1 that they want to print to instead of the
- printer on LPT1, or even 'print' to a standard file). As an example:
- {
- FILE *printer_handle;
- printer_handle = fopen("LPT1", "w");
- if (printer_handle != NULL) {
- fprintf(printer_handle, "This goes to the printer\n"
- fclose(printer_handle);
- }
- }
- Substitute a variable for "LPT1" and it can print to LPT1, LPT2,
- COM1, COM2, a file, etc...
-
- I've (hopefully) re-directed followups to comp.os.msdos.programmer
- where there will be *much* more help and this is on topic.
-
-
- Jeff
- --
- Jeff Pleimling | jap@interaccess.com
- "No, Pinky, there YOU are. I am nowhere near that vincinity." the Brain
-